<?php
namespace c\user;

/**
 * Description of g
 *
 * @author YeFng
 */
class g extends \control
{
	var $table ='user';
    /**
     * 用户名转为ID
     * 
     * @param string $n
     * @param string $mark {0}不存在返回0，{1}排除禁用的用户 ,默认适用post,搜索用10
     * @return int
     */
    function nameToID($n, $mark='01')
    {
		if (!trim($n))
			return $mark{0} ? 0 : NULL;
			
        $_n = $this->db->escape($n);
		$where = "(name='$_n' or email='$_n' or phone='$_n')";
        if ($mark{1})
            $where .= ' AND state>0';
        $id = $this->db->getOneField('user', 'id', $where);
        if ($id)
            return $id;
        return $mark{0} ? 0 : NULL;
    }
    function getName($id)
    {
        return $this->db->getOneField($this->table, 'name', 'id='. intval($id));
    }
    
    /**
     * 验证密码
     * @param string $str 明码
     * @param string $passwd  密码
     * @return boolean
     */
    function password_ver($str, $passwd)
	{
		return \encrypt::passwd($str, $passwd) == $passwd;
	}
    //加密
	function password_ed($str)
	{
		return \encrypt::passwd($str);
	}
	// is exit
	function isHas($v, $c='name')
	{
		return $this->db->getOne($this->table, '*',  $c. '="'. $this->db->escape($v)  .'"');
	}
}
